package hotLeetcode;

import java.security.Key;
import java.security.interfaces.RSAKey;

public class H010Leetcode560 {

    //暴力
    public int subarraySum(int[] nums, int k) {
        int result = 0;

        for (int left = 0; left < nums.length; left++) {
            for (int right = left; right < nums.length; right++) {
                int sum = 0;
                for (int i = left; i <= right; i++) {
                    sum += nums[i];

                }
                if (sum == k) {
                    result++;
                }

            }
        }
        return result;

    }


    //暴力优化
    public int subarraySum2(int[] nums, int k) {
        int result = 0;

        for (int left = 0; left < nums.length; left++) {
            int sum = 0;
            for (int right = left; right < nums.length; right++) {
                sum += nums[right];
                if (sum == k) {
                    result++;
                }



            }


        }
        return result;

    }



    public static void main(String[] args) {
        int[] nums = {1, 1, 1};
        int k = 2;
        H010Leetcode560 h010Leetcode560 = new H010Leetcode560();
        System.out.println(h010Leetcode560.subarraySum(nums, k));
    }
}
